<template>

  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="submitCallback"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭" okText="确认"> 
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
           <a-col :span="16">
            <a-form-item label="查询："  prop="keyword">
              <a-input-search v-model="queryParam[keywordKey]" enter-button placeholder="请输入关键词进行模糊查询" @search="searchQuery" />
            </a-form-item>
          </a-col>
         <a-button @click="searchQuery" icon="reload">刷新</a-button>
        </a-row>
      </a-form>
    </div>
    <div class="table-operator">
      <!-- <a-button @click="searchQuery" icon="reload">刷新</a-button> -->
      
    </div>
    <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">
         <a slot="fileName" slot-scope="text, record">
          <a icon="download" @click="handleViewFile(record)">{{ text }}</a>
        </a>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="receiveUser" slot-scope="text, record">
           <a-input placeholder="点击选择" v-model="record.realname" @click="selectUser(record)" />
        </span>
      
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
        </span>

      </a-table>
       
  </j-modal>
</template>

<script>
import { strNotNull } from '@/utils/common.js'
 import cloneDeep from 'lodash/cloneDeep'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { mixinDevice } from '@/utils/mixin'
  import { httpAction, getAction,postAction } from '@/api/manage'
  export default {
    name: 'PolicyForecastModal',
     mixins:[JeecgListMixin,mixinDevice],
    components: {

    },
    props: {
      isAllSelect:{
        //默认多选
        type:Boolean,
        default:true,
        required:false,
      },
      limit:{
        //限制数量
        type:Number,
        
        default:0,
        required:false
      },
      importColumns:{
        //传入表头
        type:Array,
        default:()=>{return []},
        required:false
      },
       params:{
            Type: Object,
            default: ()=>{return {}},
            require:false
      },
      keywordKey:{
          Type:String,
          default: 'keyword',
          require:false
      },
       searchPlaceholder: {
          Type: String,
          default: ''
      },
      title:{
          Type:String,
          default:'选择数据',
        
      },
      width:{
          Type:Number,
          default:800
      },
      listUrl:{
          type:String,
          
      }
    },
    data () {
      return {
      saveData:[],
      disableMixinCreated:true,
      currSel: {},
      originTargetKeys: [],
      isorter:{
        column: '',
        order: 'desc',
      },
        /* 查询条件-请不要在queryParam中声明非字符串值的属性 */
      queryParam: {},
      /* 数据源 */
      dataSource:[],
    
      /* table加载状态 */
      loading:false,
      /* table选中keys*/
      selectedRowKeys: [],
      /* table选中records*/
      selectionRows: [],

        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
        {
          title: '文件编号',
          dataIndex: 'fileNo',
          key: 'fileNo',
          fixed: 'left'
        },
        {
          title: '文件名称',
          dataIndex: 'fileName',
          key: 'fileName',
          scopedSlots: { customRender: 'fileName' },
        },
        {
          title: '发布日期',
          dataIndex: 'effectTime',
          key: 'effectTime',
        },
        ],  
        url: {
          list: "",
        },
        dictOptions:{},
        superFieldList:[],
      
        visible: false,
        disableSubmit: false
      }
    },
    watch: {
      // importColumns:function(val){
      //     this.initColums(val)
      // }
    },
    methods: {
      initColums(val){
            var rowIndex = [{
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          }]
          this.columns = [...rowIndex,...val]
      }, 
      open (urlList) {
        this.visible=true
        this.$nextTick(()=>{
        
          this.url.list = this.listUrl;
          this.queryParam =cloneDeep(this.params)
       
        this.loadData(1);
        })
      },
      edit (record) {
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.edit(record);
        })
      },
      handleViewFile(row){
        let urlJump = this.$router.resolve({ path: '/library/file/edit/' + 2 + '/' + row.id + '/' + row.draftVersion })
        window.open(urlJump.href, '_blank')
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        //返回数组
         var that = this;
        // if(that.selectedRowKeys.length <= 0){
        //    this.$message.warning('请选择数据！');
        //    return;
        // }
        
        // if(!that.isAllSelect && that.selectedRowKeys.length != 1){
        //     this.$message.warning('请选择一行数据！');
        //    return;
        // }
        //  if(that.limit !=0 && that.selectedRowKeys.length > that.limit){
        //     this.$message.warning(`最多选择${that.limit}行数据！`);
        //    return;
        // }
        // var res = []
        // for (var a = 0; a < that.selectedRowKeys.length; a++) {
        //   let rowIndex = that.selectedRowKeys[a] ;
        //   res.push(that.dataSource[rowIndex])
         
        // }
       
        
        this.$emit('ok',res);
        that.onClearSelected();
        
      },
      submitCallback(){
        this.$emit('ok');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      },
       handleDelete: function () {

    
      
    },
    handleList(){

    },
    modalFormOk(res){
      this.dataSource.push(res)
    }
    }
  }
</script>